/*是否合法IP地址*/
export function validateIP(rule: any, value: any, callback: any) {
  if (value == '' || value == undefined || value == null) {
    callback()
  } else {
    const reg =
      /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/
    if (!reg.test(value) && value != '') {
      callback(new Error('请输入正确的IP地址'))
    } else {
      callback()
    }
  }
}

export function formatDate(value: any) {
  if (!value) return ''
  if (value !== undefined || value !== '' || value != null) {
    const date = new Date(value)
    let h: any = date.getHours()
    h = h < 10 ? '0' + h : h
    let m: any = date.getMinutes()
    m = m < 10 ? '0' + m : m
    let s: any = date.getSeconds()
    s = s < 10 ? '0' + s : s
    const time = h + ' 时 ' + m + ' 分 ' + s + ' 秒 '
    return time
  }
}
